package com.huitone.gddw.service.impl.worktable;

import java.util.Date;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import com.huitone.gddw.dao.entity.PrgDispatchNotify;
import com.huitone.gddw.dao.entity.PrgRunningStatus;
import com.huitone.gddw.dao.worktable.paramconfigmanage.IPrgDispatchNotifyDao;
import com.huitone.gddw.dao.worktable.paramconfigmanage.IPrgRunningStatusDao;
import com.huitone.gddw.service.IPrgRunningStatusService;
import com.huitone.gddw.utils.StringUtils;
import com.huitone.gddw.utils.SysLoginUtil;

/**
* @Title PrgRunningStatusService
* @Package IPrgRunningStatusService
* @Description TODO
* @author chengsiyue
* @date 2017年4月22日 下午2:31:34
* @version V1.0   
*/

@Service
public class PrgRunningStatusService implements IPrgRunningStatusService{
	@Autowired
	private IPrgRunningStatusDao prgRunningStatusDao;
	@Autowired
	private IPrgDispatchNotifyDao prgDispatchNotifyDao;

	@Override
	public PrgRunningStatus selectByPrimaryKey(String prgId) {
		return prgRunningStatusDao.selectByPrimaryKey(prgId);
	}


	@Override
	public int updateByPrimaryKeySelective(PrgRunningStatus record) {
		record.setLastModTime(new Date());
		record.setLastModStaffId(SysLoginUtil.getLoginUserId());
		return prgRunningStatusDao.updateByPrimaryKeySelective(record);
	}
	@Override
	public String selectRunningStatus(String prgId){
		return prgRunningStatusDao.selectRunningStatus(prgId);
	}

	@Override
	public int updateStatus(String prgId) {
		return prgRunningStatusDao.updateStatus(prgId);
	}


	@Override
	public void changeRunningStatus(PrgRunningStatus record) {
		record.setLastModTime(new Date());
		record.setLastModStaffId(SysLoginUtil.getLoginUserId());
		prgRunningStatusDao.updateByPrimaryKeySelective(record);
		
		PrgDispatchNotify prgDispatchNotify = new PrgDispatchNotify();
		prgDispatchNotify.setRecId(StringUtils.uuid());
		prgDispatchNotify.setPrgId(record.getPrgId());
		prgDispatchNotify.setNotifyType(record.getRunningStatus());
		prgDispatchNotify.setInsertStaffId(SysLoginUtil.getLoginUserId());
		prgDispatchNotify.setInsertTime(new Date());
		prgDispatchNotifyDao.save(prgDispatchNotify);
	}

}
